package com.example.waterrecordopengl

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions

class PermissionActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_permission)
        XXPermissions.with(this)
            .permission(Permission.CAMERA)
            .permission(Permission.RECORD_AUDIO)
            .permission(Permission.WRITE_EXTERNAL_STORAGE)
            .request(object : OnPermissionCallback {
                override fun onGranted(p0: List<String?>, p1: Boolean) {
                    if (p1){
                        startActivity(Intent(this@PermissionActivity, MainActivity::class.java))
                        finish()
                    }
                }

                override fun onDenied(permissions: List<String?>, doNotAskAgain: Boolean) {
                    if (doNotAskAgain){
                        XXPermissions.startPermissionActivity(this@PermissionActivity,permissions)
                    }
                }

            })
    }
}